﻿@model thailandProject.Models.PROPERTY

@{
    ViewBag.Title = "EditProperty";
}

<div id="Wrapper2">
    <div id="content_header">
        <div id="headerimage">
        </div>
        <div id="theheader">@ViewBag.Header</div>
    </div>
    <!-- Left Column begins here -->
    <aside id="sidebar-wrapper">
        <nav class="sidebar">
            <!-- CONTENT GOES HERE -->
            @using (Html.BeginForm("EditProperty", "Admin", FormMethod.Post, new { id = "editForm" }))
            {
                string value = Model.propIsActive ? "true" : "false";
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>PROPERTY</legend>

        @Html.HiddenFor(model => model.propID)

        <div class="editor-label">
            <label for="lblEditPropertyName">Name</label>
        </div>
        <div class="editor-field">
            <input type="text" id="propName" name="propName" maxlength="20" value="@Model.propName" />
            <div id="propNameError" style="color:red; visibility:hidden;">Name cannot be empty</div>
        </div>

        <div class="editor-label">
            <label for="lblEditPropertyURL">URL</label>
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.propHyperlink, new { maxlength = 100 })
            @Html.ValidationMessageFor(model => model.propHyperlink)
        </div>

        <div class="editor-label">
            <label for="lblEditPropertyLocation">Location</label>
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.propLocation, new { maxlength = 2000 })
            @Html.ValidationMessageFor(model => model.propLocation)
        </div>

       <div class="editor-label">
            <label for="lblEditPropertyDetails">Details</label>
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.propDetails, new { id = "propDetails" })
            @Html.ValidationMessageFor(model => model.propDetails)
            <div id="charsLeft">&nbsp;</div>
        </div>

        <div class="editor-label">
            <label for="lblEditPropertyName">Is Active</label>
            <span>
                <input type="hidden" id="precheck" value="@value" />
                <input id="propIsActive" name="propIsActive" type="hidden" value="@value" />
                <img class="hideCompleted_checkbox" src="../../images/checkedBlue.png" id="checkbox" style="width:1.4em;"/>
                <img src="../../images/unchecked.png" id="image_preload" style="width:1.4em; visibility:hidden;"/>   
            </span>
        </div>

        
    </fieldset>
                
                <input type="image" src="../../images/save_button.png" value="Save" class="btnAddEditProperty" />
                <div id="formError" style="color:red; visibility:hidden">Please correct the above errors to continue</div>
            }

<div>
    @Html.ActionLink("Back to List", "ManageProperties")
</div>
        </nav>
    </aside>
    <!-- Right column begins here -->
    <article id="contents">
        
    </article>
    <!-- Right column ends here -->
</div>
<!-- Div wrapper2 ends here -->

<script>
    $(function () {
        if ($("#precheck").val() == "false") {
            $("#checkbox").attr('src', '../../images/unchecked.png');
        }
    });

    $(".hideCompleted_checkbox").click(function () {
        var indicator = 0;
        var this_id = $(this).attr('id');
        //alert(this_id);
        if ($(this).attr('src') == '../../images/unchecked.png') {
            $(this).attr('src', '../../images/checkedBlue.png');
            $("#propIsActive").val('true');
            indicator = 1;
        }
        else {
            $(this).attr('src', '../../images/unchecked.png');
            $("#propIsActive").val('false');
            indicator = 0;
        }
    })

    $("#editForm").submit(function ()
    {
        if ($("#propName").val() == "") {
            $("#propNameError").attr('style', 'color:red; visibility:visible;');
            $("#formError").attr('style', 'color:red; visibility:visible;');
            $("#propName").focus();
            return false;
        }
        else {
            $("#propNameError").attr('style', 'color:red; visibility:hidden;');
            $("#formError").attr('style', 'color:red; visibility:hidden;');
            return true;
        }
    })

    $("#propDetails").keyup(function () {
        var message = $(this).val();

        if (message.length > 2000) {
            message = message.substr(0, 2000);
            $(this).val(message);
        }

        $("#charsLeft").text(2000 - message.length + " chars left");
    })
</script>

